package com.ygnn.mapper;

import com.ygnn.common.Dto.OrderDto;
import com.ygnn.common.Pojo.Order;
import com.ygnn.common.Vo.OrderVo;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;


/**
 * ClassName:OrderMapper
 * Package:com.ygnn.mapper
 * Description:
 *
 * @Author: dlh
 * @Creat:2024/10/8-22:41
 */
@Mapper
public interface OrderMapper {
    @Insert("INSERT INTO tb_order (order_id,openid, user_id, times, km, start_date, end_date, amount, status, creat_time) VALUES(#{orderId},#{openid}, #{userId}, #{times}, #{km}, #{startDate}, #{endDate}, #{amount}, #{status}, CURRENT_TIMESTAMP)")
    void add(OrderDto orderDto);
    @Select("SELECT user_id, times, km, start_date, status FROM tb_order where status=0")
    List<OrderVo> selectAll();

    @Select("SELECT user_id, times, km, start_date,end_date, amount ,status ,creat_time FROM tb_order WHERE DATE(creat_date) = DATE(#{date})")
    List<OrderVo> selectByDate(Date date);

    //根据乐跑id查询
    @Select("SELECT user_id, times, km, start_date,end_date, amount ,status ,creat_time FROM tb_order where user_id=#{id}")
    List<OrderVo> selectById(int id);
    @Update("UPDATE tb_order SET status = #{status}, msg = #{msg} WHERE user_id = #{id}")
    void UpDateById(int id,int status,String msg);

    //查询订单状态
    @Select("SELECT * FROM tb_order where order_id=#{orderId}")
    Order selectByOrderId(Long orderId);
    //更新订单状态
    @Update("UPDATE tb_order SET status=#{status}  where order_id=#{orderId}")
    void updateByOrderId(Long orderId,int status);

    @Select("SELECT user_id, times, km, start_date,end_date, amount ,status ,creat_time FROM tb_order where openid=#{openid}")
    List<OrderVo> selectByOpenid(String openid);

}
